package com.emellend.api.datewidgets;

import com.emellend.api.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.TimePicker.OnTimeChangedListener;
/**
 * 随着时间选择器的改变，旁边的文本内容也跟着改变
 * @author emellend
 *
 */
public class DateWidgets2 extends Activity{
	private TextView mTimeDisplay;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.date_widgets_example_2);
		init();
	}

	private void init() {
		mTimeDisplay=(TextView) this.findViewById(R.id.dateDisplay);
		TimePicker timePicker = (TimePicker) this.findViewById(R.id.timePicker);
		timePicker.setCurrentHour(12);
		timePicker.setCurrentMinute(15);
		updateDisplay(12,15);
		timePicker.setOnTimeChangedListener(new OnTimeChangedListener() {
			public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
				updateDisplay(hourOfDay, minute);
			}
		});
	}

	private void updateDisplay(int hour, int minute) {
		mTimeDisplay.setText(pad(hour)+":"+pad(minute));
	}
	private static String pad(int c) {
        if (c >= 10)
            return String.valueOf(c);
        else
            return "0" + String.valueOf(c);
    }
	

}
